What is the limit on how many numbers can be added up with this program?

Answer:

There is no limit. As long as the user does not enter a 0, the program is happy to keep adding. This is a big advantage. Often you want a program to run until you tell it to stop. (Much like a car—you want it to keep running until you are done with it. It would be awkward if you had to tell your car exactly how far you wanted it to go at the beginning of each trip.)

Advantage of Sentinels

A big advantage of using sentinel values is that there is no limit to how many times a loop can execute, and that it ends gracefully when it is done.

If the user keeps entering big numbers, soon the sum will be too large for the computer to handle. This is just like a hand calculator that has a limit on how large a number it can hold. But if the user were entering both negative and positive numbers, the sum might never get too large. Then the program could keep going and going.

Other Sentinel Values

A sentinel value should be a value that is never going to appear in data. Adding zero to a sum does not change the sum, so the program to add numbers could use zero as a sentinel value. If the list of numbers the user were adding had a zero in it, the user could just skip it without changing the sum.

Sometimes you know that there will never be any negative numbers in a list of numbers to add. The program could be changed so that any negative number acted as a sentinel value. Here is the program, with a blank in the loop condition:

' Add up numbers that the user enters.
' When the user enters any negative number, 
' print the sum and end the program.
'
LET SUM = 0
'
PRINT "Enter a positive number"       
INPUT NUMBER                 
'
DO WHILE NUMBER ______ 0

  LET SUM = SUM + NUMBER   
  PRINT "Enter a positive number."       
  INPUT NUMBER                 
LOOP
'
PRINT "The sum is", SUM
END

QUESTION 15:

Pick a symbol to put in the blank in the program. The loop body will not execute when the user types a negative number. Choose from the available comparisons:

= equal
< less than
<= less than or equal
> greater than
>= greater than or equal
<> not equal